package com.zhijian.warehouse.manage.controller.app;

import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import com.zhijian.warehouse.manage.entity.dto.UserDto;
import com.zhijian.warehouse.manage.entity.vo.request.WarehouseLocationSaveOrUpdateVo;
import com.zhijian.warehouse.manage.entity.vo.request.WarehouseLocationSearchVo;
import com.zhijian.warehouse.manage.entity.vo.response.WarehouseLocationVo;
import com.zhijian.warehouse.manage.enums.DelFlagEnum;
import com.zhijian.warehouse.manage.holder.CurrentMpUserHolder;
import com.zhijian.warehouse.manage.holder.CurrentWebUserHolder;
import com.zhijian.warehouse.manage.service.WarehouseLocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 仓库库位 控制层
 *
 * @author auto
 * @version 1.0
 * @date 2024-10-10 19:40:29
 */
@Slf4j
@Controller
@Api(tags = "app仓库库位")
@RequestMapping("/app")
public class AppWarehouseLocationController {

    @Autowired
    private WarehouseLocationService service;


    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/warehouse/location/{id}")
    @ApiOperation("根据id查询")
    public WarehouseLocationVo selectById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/warehouse/location/page")
    @ApiOperation("分页查询")
    public Page<WarehouseLocationVo> selectByCondition(@RequestBody(required = false) WarehouseLocationSearchVo param) {
        if (param == null)
            param = WarehouseLocationSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        param.setIsDelete(DelFlagEnum.USING.value);
        param.setStatus((byte)1);
        return service.selectPage(param);
    }

    /**
     * 列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/warehouse/location/list")
    @ApiOperation("列表查询")
    public List<WarehouseLocationVo> selectList(@RequestBody(required = false) WarehouseLocationSearchVo param) {
        if (param == null)
            param = WarehouseLocationSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        param.setIsDelete(DelFlagEnum.USING.value);
        param.setStatus((byte)1);
        return service.selectList(param);
    }

    /**
     * 修改条码绑定
     *
     * @param param
     * @return
     */
    @Response
    @PutMapping("/warehouse/location/binding/barcode")
    @ApiOperation("库位 条码绑定 入参 库位id 和编码 barCode")
    public boolean bindingBarcode( @RequestBody WarehouseLocationSaveOrUpdateVo param) {
        UserDto user = CurrentMpUserHolder.getUser();
        param.setUpdateUserId(user.getId());
        param.setUpdateUserName(user.getName());
        log.info("{} - {}| bindingBarcode info, {}", this.getClass().getSimpleName(), param);
        return service.bindingBarcode(param);
    }


    /**
     * 根据条码查询库位
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/warehouse/location/sel/barcode")
    @ApiOperation("根据条码查询库位")
    public WarehouseLocationVo selectByBarcode(@RequestBody WarehouseLocationSearchVo param) {
        log.info("{} - {}| selectByBarcode info", this.getClass().getSimpleName(), param);
        if (param == null)
            param = WarehouseLocationSearchVo.builder().build();
        param.setIsDelete(DelFlagEnum.USING.value);
        param.setStatus((byte)1);
        return service.selectByBarCode(param);
    }
}
